﻿<local:StructViewBase xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" 
    x:Class="AdminModule.UserControls.StructView.IndexMarkStruct"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:AdminModule.UserControls.StructView"
    xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:classes="clr-namespace:AdminModule.CustomXAMLElements"
    xmlns:validation="clr-namespace:InpValidator"
    xmlns:converters="clr-namespace:AdminModule.Converters"
    xmlns:vm="clr-namespace:AdminModule.ViewModels"
    xmlns:sharedCode="clr-namespace:SharedCode;assembly=SharedCode">
    
    <local:StructViewBase.Resources>
        <vm:CommonVM2 x:Key="commonVM"></vm:CommonVM2>
        <converters:NullToBlankConverter x:Key="nullToBlankConverter"></converters:NullToBlankConverter>
        <converters:BoolToVisibilityConverter x:Key="boolToVisibilityConverter"></converters:BoolToVisibilityConverter>

        <common:HierarchicalDataTemplate  x:Key="SectionLevel1" ItemsSource="{Binding Path=Childs2, Mode=TwoWay}">

            <classes:TemplateSelector Content="{Binding}">
                <classes:TemplateSelector.Templates>

                    <classes:IMDataTemplate IMName="AdmBaseClass">
                        <StackPanel Visibility="{Binding IsVisibility, Converter={StaticResource boolToVisibilityConverter}, Mode=TwoWay}" />
                    </classes:IMDataTemplate>

                    <classes:IMDataTemplate IMName="AdmGradation">
                        <StackPanel Orientation="Horizontal">
                            <StackPanel Orientation="Horizontal">
                                <CheckBox ToolTipService.ToolTip="Обязателен для заполнения" VerticalAlignment="Center" Loaded="IsNecessaryCheckBox_Loaded" Tag="{Binding}" x:Name="IsNecessaryCheckBox" IsChecked="{Binding Path=IsNecessary, Mode=TwoWay}"></CheckBox>
                                <TextBlock VerticalAlignment="Center" Padding="0" Text="{Binding Path=Order}" />
                                <TextBlock VerticalAlignment="Center" Padding="0" Text=". " />
                                <TextBlock VerticalAlignment="Center" Padding="0" Text="{Binding Path=Name, Mode=TwoWay}" />
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Loaded="gradationWeightStackPanel_Loaded" Tag="{Binding}" x:Name="gradationWeightStackPanel">
                                    <TextBlock VerticalAlignment="Center" Padding="0" Text=" (вес: "/>
                                    <TextBlock VerticalAlignment="Center" FontWeight="Bold" Padding="0" Text="{Binding Path=Weight, Mode=TwoWay}" />
                                    <TextBlock VerticalAlignment="Center" Padding="0" Text=")"/>
                                </StackPanel>

                                <ToolTipService.ToolTip>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="IDGradationTerm: "></TextBlock>
                                        <TextBlock Text="{Binding IDGradationTerm}"></TextBlock>
                                        <TextBlock Text=", "></TextBlock>
                                        <TextBlock Text="IDGradation: "></TextBlock>
                                        <TextBlock Text="{Binding ID}"></TextBlock>
                                    </StackPanel>
                                </ToolTipService.ToolTip>
                            </StackPanel>
                            <TextBox MaxHeight="20" BorderBrush="#ffd9d9d9" BorderThickness="1" ToolTipService.ToolTip="Нижняя граница" Padding="0" Loaded="gradationLimit_Loaded" Tag="{Binding}" Width="50" x:Name="gradationBottomLimit" Margin="5,0,0,0" Text="{Binding BottomLimitTxtBox, Mode=TwoWay}"></TextBox>
                            <TextBox MaxHeight="20" BorderBrush="#ffd9d9d9" BorderThickness="1" ToolTipService.ToolTip="Верхняя граница" Padding="0" Loaded="gradationLimit_Loaded" Tag="{Binding}" Width="50" x:Name="gradationTopLimit" Margin="5,0,0,0" Text="{Binding TopLimitTxtBox, Mode=TwoWay}"></TextBox>
                        </StackPanel>
                    </classes:IMDataTemplate>

                    <classes:IMDataTemplate IMName="AdmCharacteristic">
                        <StackPanel Orientation="Vertical">
                            <StackPanel Orientation="Horizontal">
                                <ComboBox ToolTipService.ToolTip="Категория" Background="{x:Null}" BorderThickness="1" BorderBrush="#ffd9d9d9" SelectionChanged="categoryComboBox_SelectionChanged" Loaded="categoryComboBox_Loaded" x:Name="categoryComboBox" Tag="{Binding}"  ItemsSource="{Binding Categories, Source={StaticResource commonVM}, Mode=TwoWay}">
                                    <ComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <Image Source="{Binding Path=ImagePath}" Width="20" Height="20">
                                                <ToolTipService.ToolTip>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="{Binding Name}"></TextBlock>
                                                        <TextBlock Text=" (вес: "></TextBlock>
                                                        <TextBlock Text="{Binding Weight}"></TextBlock>
                                                        <TextBlock Text=")"></TextBlock>
                                                    </StackPanel>
                                                </ToolTipService.ToolTip>
                                            </Image>
                                        </DataTemplate>
                                    </ComboBox.ItemTemplate>
                                    <validation:ValidatorService.Validator>
                                        <validation:ComboBoxNotNullValidator Init="InitValidator" />
                                    </validation:ValidatorService.Validator>
                                </ComboBox>
                                <TextBox ToolTipService.ToolTip="Номер" VerticalAlignment="Center" FontStyle="Italic" BorderThickness="0" Padding="0" Text="{Binding Path=Order, Mode=TwoWay}">
                                    <validation:ValidatorService.Validator>
                                        <validation:NotEmptyValidator Init="InitValidator" />
                                    </validation:ValidatorService.Validator>
                                </TextBox>
                                <TextBlock VerticalAlignment="Center" FontStyle="Italic" Padding="0" Text=" - "/>
                                <TextBlock VerticalAlignment="Center" FontStyle="Italic" Padding="0" Text="{Binding Path=Name, Mode=TwoWay}">
                                    <ToolTipService.ToolTip>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="IDCharacteristicTerm: "></TextBlock>
                                            <TextBlock Text="{Binding IDCharacteristicTerm}"></TextBlock>
                                            <TextBlock Text=", "></TextBlock>
                                            <TextBlock Text="IDCharacteristic: "></TextBlock>
                                            <TextBlock Text="{Binding ID}"></TextBlock>
                                            <TextBlock Text=", "></TextBlock>
                                            <TextBlock Text="IDCategorySectionTerm: "></TextBlock>
                                            <TextBlock Text="{Binding IDCategorySectionTerm}"></TextBlock>
                                        </StackPanel>
                                    </ToolTipService.ToolTip>
                                </TextBlock>
                                <TextBlock VerticalAlignment="Center" FontStyle="Italic" Padding="0" Text=" (вес: "/>
                                <TextBox VerticalAlignment="Center" FontStyle="Italic" BorderThickness="0" Padding="0" Text="{Binding Path=Weight, Mode=TwoWay}">
                                    <validation:ValidatorService.Validator>
                                        <validation:CompositValidator Init="InitValidator">
                                            <validation:CompositValidator.Childs>
                                                <validation:CheckDoubleValidator />
                                                <validation:ValueMoreThenZeroValidator />
                                            </validation:CompositValidator.Childs>
                                        </validation:CompositValidator>
                                    </validation:ValidatorService.Validator>
                                </TextBox>
                                <TextBlock VerticalAlignment="Center" FontStyle="Italic" Padding="0" Text=", ед. изм.: "/>
                                <ComboBox Background="{x:Null}" BorderThickness="1" BorderBrush="#ffd9d9d9" Loaded="unitComboBox_Loaded" SelectionChanged="unitComboBox_SelectionChanged" x:Name="unitComboBox" Tag="{Binding}" ItemsSource="{Binding Units, Source={StaticResource commonVM}, Mode=TwoWay}">
                                    <ComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Name}">
                                                <ToolTipService.ToolTip>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="IDUnit: "></TextBlock>
                                                        <TextBlock Text="{Binding IDUnit}"></TextBlock>
                                                    </StackPanel>
                                                </ToolTipService.ToolTip>
                                            </TextBlock>
                                        </DataTemplate>
                                    </ComboBox.ItemTemplate>
                                    <validation:ValidatorService.Validator>
                                        <validation:ComboBoxNotNullValidator Init="InitValidator" />
                                    </validation:ValidatorService.Validator>
                                </ComboBox>
                                <TextBlock VerticalAlignment="Center" FontStyle="Italic" Padding="0" Text=")"/>
                                <CheckBox Margin="3,0,0,0" VerticalAlignment="Center" IsChecked="{Binding Visibility, Mode=TwoWay}" ToolTipService.ToolTip="Видимый показатель"></CheckBox>
                                <CheckBox Margin="3,0,0,0" VerticalAlignment="Center" IsChecked="{Binding IndexRequired, Mode=TwoWay}" ToolTipService.ToolTip="Обязателен для учёта в Индексной системе"></CheckBox>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <controlsToolkit:Expander IsExpanded="False" ExpandDirection="Down">
                                    <controlsToolkit:Expander.Content>
                                        <ListBox BorderThickness="0" ItemsSource="{Binding Path=Responsibles}">
                                            <ListBox.ItemTemplate>
                                                <DataTemplate>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="● "></TextBlock>
                                                        <TextBlock Text="{Binding Path=Position.Name}"></TextBlock>
                                                        <TextBlock Text=" ("></TextBlock>
                                                        <!--Вставим тире, если отдел == NULL-->
                                                        <TextBlock Text="{Binding Path=Department, Converter={StaticResource nullToBlankConverter}}"></TextBlock>
                                                        <TextBlock Text="{Binding Path=Department.Name}"></TextBlock>
                                                        <TextBlock Text=")"></TextBlock>

                                                        <ToolTipService.ToolTip>
                                                            <StackPanel Orientation="Horizontal">
                                                                <TextBlock Text="IDResponsible: "></TextBlock>
                                                                <TextBlock Text="{Binding IDResponsible}"></TextBlock>
                                                            </StackPanel>
                                                        </ToolTipService.ToolTip>
                                                    </StackPanel>
                                                </DataTemplate>
                                            </ListBox.ItemTemplate>
                                        </ListBox>
                                    </controlsToolkit:Expander.Content>
                                        
                                    <controlsToolkit:Expander.HeaderTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <HyperlinkButton x:Name="positionSelectHyperlink" Click="positionSelectHyperlink_Click2" Foreground="Gray" Content="Ответственные..."></HyperlinkButton>
                                            </StackPanel>
                                        </DataTemplate>
                                    </controlsToolkit:Expander.HeaderTemplate>
                                </controlsToolkit:Expander>
                                <TextBox MaxHeight="20" BorderBrush="Black"  BorderThickness="1" ToolTipService.ToolTip="Количество периодов" Padding="0" Tag="{Binding}" Width="50" Margin="5,0,0,0" Text="{Binding VolumeValidPeriod, Mode=TwoWay}">
                                    <validation:ValidatorService.Validator>
                                        <validation:CompositValidator Init="InitValidator">
                                            <validation:CompositValidator.Childs>
                                                <validation:CheckDoubleValidator />
                                                <validation:ValueMoreThenZeroValidator />
                                            </validation:CompositValidator.Childs>
                                        </validation:CompositValidator>
                                    </validation:ValidatorService.Validator>
                                </TextBox>
                                <TextBox MaxHeight="20" BorderBrush="#ffd9d9d9" BorderThickness="1" ToolTipService.ToolTip="Нижняя граница" Padding="0" Loaded="characteristicLimit_Loaded" Tag="{Binding}" Width="50" x:Name="characteristicBottomLimit" Margin="5,0,0,0" Text="{Binding BottomLimitTxtBox, Mode=TwoWay}"></TextBox>
                                <TextBox MaxHeight="20" BorderBrush="#ffd9d9d9" BorderThickness="1" ToolTipService.ToolTip="Верхняя граница" Padding="0" Loaded="characteristicLimit_Loaded" Tag="{Binding}" Width="50" x:Name="characteristicTopLimit" Margin="5,0,0,0" Text="{Binding TopLimitTxtBox, Mode=TwoWay}"></TextBox>
                            </StackPanel>
                        </StackPanel>
                    </classes:IMDataTemplate>

                    <classes:IMDataTemplate IMName="AdmSection">
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/IndexMarkSilverlightClient;Component/Views/Resources/Folder_Closed.png" Width="20" Height="20"/>
                            <TextBox ToolTipService.ToolTip="Номер" BorderThickness="0" Padding="0" Text="{Binding Path=Order, Mode=TwoWay}">
                                <validation:ValidatorService.Validator>
                                    <validation:NotEmptyValidator Init="InitValidator" />
                                </validation:ValidatorService.Validator>
                            </TextBox>
                            <TextBlock Text=" - "/>
                            <TextBlock Padding="0" Text="{Binding Path=Name, Mode=TwoWay}">
                                <ToolTipService.ToolTip>
                                    <StackPanel Orientation="Vertical">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Кол-во разделов: "></TextBlock>
                                            <TextBlock FontWeight="Bold" Text="{Binding SectionsCount}"></TextBlock>
                                            <TextBlock Text=", кол-во показателей: "></TextBlock>
                                            <TextBlock FontWeight="Bold" Text="{Binding CharacteristicsCount}"></TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="IDSectionTerm: "></TextBlock>
                                            <TextBlock Text="{Binding IDSectionTerm}"></TextBlock>
                                            <TextBlock Text=", "></TextBlock>
                                            <TextBlock Text="IDSection: "></TextBlock>
                                            <TextBlock Text="{Binding ID}"></TextBlock>
                                        </StackPanel>
                                    </StackPanel>
                                </ToolTipService.ToolTip>
                            </TextBlock>
                            <TextBlock Text=" (вес: "/>
                            <TextBox BorderThickness="0" Padding="0" Text="{Binding Path=Weight, Mode=TwoWay}">
                                <validation:ValidatorService.Validator>
                                    <validation:CompositValidator Init="InitValidator">
                                        <validation:CompositValidator.Childs>
                                            <validation:CheckDoubleValidator />
                                            <validation:ValueMoreThenZeroValidator />
                                        </validation:CompositValidator.Childs>
                                    </validation:CompositValidator>
                                </validation:ValidatorService.Validator>
                            </TextBox>
                            <TextBlock Text=")"/>
                            <CheckBox Margin="3,0,0,0" VerticalAlignment="Center" IsChecked="{Binding Participate, Mode=TwoWay}" ToolTipService.ToolTip="Участвует в расчёте индексов"></CheckBox>
                        </StackPanel>
                    </classes:IMDataTemplate>

                </classes:TemplateSelector.Templates>
            </classes:TemplateSelector>

        </common:HierarchicalDataTemplate>

        <common:HierarchicalDataTemplate x:Key="SectionRootLevel" ItemsSource ="{Binding Path=Childs2, Mode=TwoWay}" ItemTemplate="{StaticResource SectionLevel1}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Padding="0" Loaded="rootNode_Loaded" Text="{Binding Path=Name, Mode=TwoWay}" FontWeight="Bold" />
            </StackPanel>
        </common:HierarchicalDataTemplate>
    </local:StructViewBase.Resources>
  
</local:StructViewBase>
